﻿using Super_Management_Mayhem.Content.Spritesheet;
using Transformable_Engine_v2.Engine.Animation.RotationAnimation;
using Transformable_Engine_v2.Engine.Animation.ScaleAnimation;
using Transformable_Engine_v2.Engine.GameObjects.Containers;
using Transformable_Engine_v2.Engine.Graphics;
using Transformable_Engine_v2.Engine.Helper;
using Transformable_Engine_v2.Engine.Time;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Super_Management_Mayhem.Screens.Playing.Players.Hud
{
    public class StartCountdown : ImageContainer
    {
        private Timer _countDownTimer;
        public StartCountdown(int delay)
        {
            AddTimers(_countDownTimer = new Timer(1000, true, ChangeSprite));

            CallMethod(delay, Start);
            Die(delay + 3000);

            Visible = false;
        }

        void Start()
        {
            Visible = true;
            _countDownTimer.Start();
            ChangeSprite();
        }

        void ChangeSprite()
        {
            ClearAnimation();
            switch (_countDownTimer.AlarmCount)
            {
                case 0:
                    Sprite = UISheet.GetSprite(UISheet.Countdown.Three);
                    Scale = new TE_Vector2(4, 4);
                    Rotation = (-0.0625);
                    AddAnimations(new ScaleUniformLinearAnimation(0, new TE_Vector2(-2, -2)));
                    AddAnimations(new RotationUniformLinearAnimation(0, 0.15f));
                    break;
                case 1:
                    Sprite = UISheet.GetSprite(UISheet.Countdown.Two);
                    Scale = new TE_Vector2(3, 3);
                    Rotation = (0.0625);
                    AddAnimations(new ScaleUniformLinearAnimation(0, new TE_Vector2(-2, -2)));
                    AddAnimations(new RotationUniformLinearAnimation(0, -0.15f));
                    break;
                case 2:
                    Sprite = UISheet.GetSprite(UISheet.Countdown.One);
                    Scale = new TE_Vector2(2, 2);
                    Rotation = (-0.0625);
                    AddAnimations(new ScaleUniformLinearAnimation(0, new TE_Vector2(-2, -2)));
                    AddAnimations(new RotationUniformLinearAnimation(0, 0.15f));
                    break;
            }

            Origin = TE_Rectangle.Alignment.CenterMiddle;
        }
    }
}